# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libsoup
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.62.2
pkgrel=1
pkgdesc="HTTP client/server library (mingw-w64)"
arch=(any)
url="https://download.gnome.org/sources/libsoup"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "intltool")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-glib-networking"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-sqlite3")
options=('staticlibs' 'strip')
source=("https://download.gnome.org/sources/${_realname}/${pkgver:0:4}/${_realname}-${pkgver}.tar.xz"
        0006-change-pkg-config-invocations.mingw.patch)
sha256sums=('9e536fe3da60b25d2c63addb84a9d5072d00b0d8b8cbeabc629a6bcd63f879b6'
            '270c8115992d4ddce526da67bbadea49ad1710f83b7a78db128dfd433372f285')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i ${srcdir}/0006-change-pkg-config-invocations.mingw.patch

  autoreconf -fi
}

build() {
  #CPPFLAGS+=" --save-temps"
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  mkdir -p docs/reference/html
  cp -rf ../${_realname}-${pkgver}/docs/reference/html/* docs/reference/html

  # an argument passed to glib-mkenums starts with a c++ comment
  export MSYS2_ARG_CONV_EXCL="/*"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --without-apache-httpd \
    --without-apache-module-dir \
    --with-gnome \
    --without-krb5-config \
    --enable-vala \
    --enable-introspection \
    --disable-silent-rules

  make #-j1 V=1
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
